<?php
namespace app\store\controller;
use think\Db;
use think\request;
use think\Controller;
class Order extends Controller
{
	protected function _initialize() {
		header('Access-Control-Allow-Origin:*');
	}
		   /* 
	 * 获取订单
	 */
	public function orders(){
		$where['status']=["neq",8];
		$where['type']=4;
		$where['add_time']=[">=",'2018-3-14'];
		$where['id']=['in','13,72'];
		$status=0;
		if(input("status")){//订单状态
			$status=input("status");
			$where['status']=input("status");
		}
		$this->assign("status",$status);
		$field="id,sn";
		$list=db("agent_syorder")->field($field)->where($where)->select();
		$list1=array();
		if($list){
			foreach($list as $k=>$v){
				$list1[$v['id']]=$v;
			}
			$order_ids = array_keys($list1);
			$field="b.goods_name as name,a.num,a.price,b.thumb,a.order_id";
			$order_items = db("agent_syorder_items")->
			alias("a")->join("agent_goods b"," a.goods_id=b.id")
			->field($field)->where("a.order_id","in",$order_ids)->select();
			foreach($order_items as $k1=>$v1){
				 $list1[$v1['order_id']]['items'][]=$v1;
			}
		}
		if($list1){
			array_multisort($list1,SORT_DESC);
		}
		$this->assign("list",$list1);
		return $this->fetch();
	}
}
